//
//  TripDetailViewController.m
//  RoadLine
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 RedFireNoodles. All rights reserved.
//
//KennethWang 日记详情
#import "TripDetailViewController.h"
#import "TripDiaryDetailCell.h"
#import "UIImageView+WebCache.h"
#import "AFHTTPRequestOperationManager.h"
#import "TripDetailViewModel.h"
#import "Singleton.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface TripDetailViewController ()
@property(nonatomic, retain)NSMutableArray *array;
@property(nonatomic ,retain)UIScrollView *scrollView;
@property(nonatomic, retain)UIImageView *tripDetailImageView;
@property(nonatomic, retain)UITextView *tripDetailtext;
@property(nonatomic, retain)UIView *backgroundView;

@end

@implementation TripDetailViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"日记详情";
        // 隐藏Navigation返回键的文字;
        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];
        self.array = [NSMutableArray array];
    }
    return self;
}
// AFN解析数据;
//- (void)analysisLoading
//{
//
//    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
//    NSString *path = [NSString stringWithFormat:@"http://api.breadtrip.com/trips/%@/waypoints/%@/",self.trip_id,self.tripDetailViewId];
//    [manager GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        // AFN解析过程
//        // 最外层字典;
//        NSMutableDictionary *dicOut = responseObject;
//        TripDetailViewModel *tripDetailViewModel = [[TripDetailViewModel alloc]init];
//        [tripDetailViewModel setValuesForKeysWithDictionary:dicOut];
//        [self.array addObject:tripDetailViewModel];
//        NSLog(@"%@",dicOut);
//        for (TripDetailViewModel *tripDetailViewModel in self.array) {
//            self.tripDetailLabel.text = tripDetailViewModel.text;
//            NSString *str = tripDetailViewModel.photo;
//            NSURL *url = [NSURL URLWithString:str];
//            [self.tripDetailImageView sd_setImageWithURL:url];
//            
//        }
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        NSLog(@"%@", error);
//    }];
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 改变uinavigationBar 的title颜色
    UILabel *titleLabelPrice = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    titleLabelPrice.font = [UIFont boldSystemFontOfSize:18];
    titleLabelPrice.textColor = [UIColor whiteColor];
    titleLabelPrice.backgroundColor = [UIColor clearColor];
    titleLabelPrice.text = @"   日记详情";
    self.navigationItem.titleView = [titleLabelPrice autorelease];
    
    // 先建一个底层的SCRollView 并设置纵向滚动的最大尺寸
    self.scrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.scrollView.contentSize = CGSizeMake(64, HEIGHT - 64);
    self.scrollView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    [self.view addSubview:self.scrollView];
    [_scrollView release];
    
    //背景图层
    self.backgroundView = [[UIView alloc] initWithFrame:CGRectMake(5, HEIGHT * 3 / 4 - 70, WIDTH - 10, HEIGHT / 4 - 50)];
    self.backgroundView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    self.backgroundView.alpha = 0.7;
    self.backgroundView.layer.cornerRadius = 8;
    self.backgroundView.tag = 10001;
    [self.view addSubview:self.backgroundView];
    [_backgroundView release];
    
    // 建一个textView
    self.tripDetailtext = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, WIDTH-10, HEIGHT/4 - 50)];
    self.tripDetailtext.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    self.tripDetailtext.textColor = [UIColor blackColor];
    self.tripDetailtext.backgroundColor = [UIColor clearColor];
    self.tripDetailtext.editable = NO;
    self.tripDetailtext.scrollEnabled = YES;
    self.tripDetailtext.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    self.tripDetailtext.layer.cornerRadius = 8;
    [self.backgroundView addSubview:self.tripDetailtext];
    [_tripDetailtext release];
    
    // 图片设置
    self.tripDetailImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, WIDTH-10, HEIGHT*3/4-80)];
    // 以下三行代码 为图片自适应
    self.tripDetailImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.tripDetailImageView.autoresizesSubviews = YES;
    self.tripDetailImageView.clipsToBounds = YES;
    self.tripDetailImageView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    [self.scrollView addSubview:self.tripDetailImageView];
    [_tripDetailImageView release];

    
    
    // 属性传值第三步:传值
    self.tripDetailtext.text = self.tripDetailViewText;
    [self.tripDetailImageView sd_setImageWithURL:[NSURL URLWithString:self.tripDetailViewUrl]  placeholderImage:[UIImage imageNamed:@"BEIJING.png"]];
    
    // 本页的夜间模式
    if ([Singleton shareSingleton].isNight) {
        [[Singleton shareSingleton]loadNightModeInfoFormDisk];
    }else{
        [Singleton shareSingleton ];
    }
    
}
// 夜间模式颜色调节
- (void)setLightDayModel
{
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:1];
    self.scrollView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    self.tripDetailtext.textColor = [UIColor blackColor];
    self.tripDetailImageView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    self.backgroundView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    
    
}
//夜间模式颜色调节:
- (void)setNightDayModel
{
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:4/255.0 green:165/255.0 blue:171/255.0 alpha:1];
    self.scrollView.backgroundColor = [UIColor colorWithRed:5/255.0 green:10/255.0 blue:23/255.0 alpha:1];
    self.tripDetailtext.textColor = [UIColor whiteColor];
    self.tripDetailImageView.backgroundColor = [UIColor clearColor];
    self.backgroundView.backgroundColor = [UIColor colorWithRed:5/255.0 green:10/255.0 blue:23/255.0 alpha:1];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
// 内存管理
- (void)dealloc
{
    [_tripDetailImageView release];
    [_array release];
    [_tripDetailtext release];
    [_scrollView release];
    [_backgroundView release];
    [super dealloc];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
